package com.controller;

import com.aop.SystemLog;
import com.dao.StudentDao;
import com.dto.DTO;
import com.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Controller //@Controller注解是用spring容器生成 对象 默认对象名 studentController
@RequestMapping("/studentController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /studentController
public class StudentController {
	@Resource
	StudentDao studentDao;
	@RequestMapping("/getAllStudent")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Student> getAllStudent(){
    	System.out.println("查询全部学生");
    	List<Student> students =  studentDao.getAllStudents();
    	return new DTO<Student>(200, "查询全部学生",students);
    }

	@RequestMapping("/selectBySnoWithScs/{sno}")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
	public DTO<Student> selectBySnoWithScs(@PathVariable("sno") String sno){
		System.out.println("查询学生选课");
		Student student =  studentDao.selectBySnoWithScs(sno);
		return new DTO<Student>(200, "查询全部学生",null,student);
	}

	@RequestMapping("/selectBySnoWithClazz/{sno}")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
	public DTO<Student> selectBySnoWithClazz(@PathVariable("sno") String sno){
		System.out.println("查询学生选课");
		Student student =  studentDao.selectBySnoWithClazz(sno);
		return new DTO<Student>(200, "查询全部学生",null,student);
	}

	@RequestMapping("/selectBySnoWithScsAndClazz/{sno}")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
	@SystemLog(module = "学生管理",methods = "根据学号查询学生附带该名学生的选课信息和班级信息")
	public DTO<Student> selectBySnoWithScsAndClazz(@PathVariable("sno") String sno){
		System.out.println("查询学生选课");
		Student student =  studentDao.selectBySnoWithScsAndClazz(sno);
		return new DTO<Student>(200, "根据学号查询学生附带该名学生的选课信息和班级信息",null,student);
	}

	@RequestMapping("/selectBySnoWithScsAndCourse/{sno}")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
	public DTO<Student> selectBySnoWithScsAndCourse(@PathVariable("sno") String sno){
		System.out.println("查询学生选课带课程信息");
		Student student =  studentDao.selectBySnoWithScsAndCourse(sno);
		return new DTO<Student>(200, "查询学生选课带课程信息",null,student);
	}

	@RequestMapping("/selectBySnoWithClazzANDTeacher/{sno}")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
	public DTO<Student> selectBySnoWithClazzANDTeacher(@PathVariable("sno") String sno){
		System.out.println("查询学生班级和班主任");
		Student student =  studentDao.selectBySnoWithClazzANDTeacher(sno);
		return new DTO<Student>(200, "查询学生班级和班主任",null,student);
	}





	@RequestMapping("/deleteStudentById/{aId}")
	@ResponseBody
    public DTO<Student> deleteStudentById(@PathVariable("aId") String aId){//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(aId+"删除学生");
    	return new DTO<Student>(200, "删除"+aId+"学生成功");
    }

}
